package com.woniu.his.sms.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.result.Result;
import com.woniu.his.sms.client.SmsRegistrationRankClient;
import com.woniu.his.sms.client.param.AddRegistrationRankClientParam;
import com.woniu.his.sms.client.param.QueryRegistrationRankClientParam;
import com.woniu.his.sms.client.param.UpdateRegistrationRankClientParam;
import com.woniu.his.sms.client.result.PageRegistrationRankResult;
import com.woniu.his.sms.client.result.RegistrationRankResult;
import com.woniu.his.sms.service.RegistrationRankService;
import com.woniu.his.sms.service.dto.PageRegistrationRankDto;
import com.woniu.his.sms.service.dto.RegistrationRankDto;
import com.woniu.his.sms.service.param.AddRegistrationRankParam;
import com.woniu.his.sms.service.param.QueryRegistrationRankParam;
import com.woniu.his.sms.service.param.UpdateRegistrationRankParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;

/**
 * @version: java version 1.8
 * @Author: ZJH
 * @description:
 * @date: 2022-11-26 15:09
 */
@RestController
@RequestMapping("sms")
@Slf4j
public class SmsRegistrationApiImpl implements SmsRegistrationRankClient {

    @Resource
    private RegistrationRankService registrationRankService;


    @Override
    public Result addRegistrationRank(AddRegistrationRankClientParam param) {
        log.info("新增挂号等级参数：{}",param);
        registrationRankService.addRegistrationRank(BeanUtil.copyProperties(param,AddRegistrationRankParam.class));
        return Result.getInstance();
    }

    @Override
    public Result deleteRegistrationRankByIds(List<Long> rankIds) {
        log.info("删除挂号等级参数ids：{}",rankIds);
        registrationRankService.deleteRegistrationRankByIds(rankIds);
        return Result.getInstance();
    }

    @Override
    public Result<PageRegistrationRankResult> queryRegistrationRank(QueryRegistrationRankClientParam param) {
        log.info("模糊查询挂号等级参数：{}",param);
        PageRegistrationRankDto pageRegistrationRankDto = registrationRankService.queryRegistrationRank(BeanUtil.copyProperties(param, QueryRegistrationRankParam.class));
        return Result.getInstance(PageRegistrationRankResult.class).setData(BeanUtil.copyProperties(pageRegistrationRankDto,PageRegistrationRankResult.class));
    }

    @Override
    public Result<List<RegistrationRankResult>> queryAllRegistrationRank() {
        log.info("查询所有挂号等级");
        List<RegistrationRankDto> registrationRankDtos = registrationRankService.queryAllRegistrationRank();
        List<RegistrationRankResult> registrationRankResults = BeanUtil.copyToList(registrationRankDtos, RegistrationRankResult.class);
        return Result.getInstanceList(RegistrationRankResult.class).setData(registrationRankResults);
    }

    @Override
    public Result<RegistrationRankResult> updateRegistrationRank(UpdateRegistrationRankClientParam param) {
        log.info("更新挂号等级信息参数：{}",param);
        RegistrationRankDto registrationRankDto = registrationRankService.updateRegistrationRank(BeanUtil.copyProperties(param, UpdateRegistrationRankParam.class));
        return Result.getInstance(RegistrationRankResult.class).setData(BeanUtil.copyProperties(registrationRankDto,RegistrationRankResult.class));
    }
}
